﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Portal.BO.Editoral.Category;
namespace Portal.GUI.EditoralOffice.MainOffce.Statistic
{
    public partial class StatContent : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string strCats=CategoryHelper.Treebuild(cboCategory);
                //string strcpmode = Request.QueryString["cpmode"].ToString();
                
                objListNewsSource.SelectParameters[0].DefaultValue = "News_Status=3";
            }
            objListNewsSource.SelectParameters[1].DefaultValue = "false";
            
        }
       

        protected void grdListNews_PageIndexChanged(object sender, EventArgs e)
        {
           
        }

        
        private string getCheckedRow()
        {
            string strDel = "";
            foreach (GridViewRow grdRow in this.grdListNews.Rows)
            {
                if (grdRow.RowType == DataControlRowType.DataRow)
                {
                    CheckBox chkSel = (CheckBox)grdRow.Cells[0].FindControl("chkSelect");
                    if (chkSel.Checked)
                    {
                        ImageButton btnItem = (ImageButton)grdRow.Cells[8].FindControl("btnApproval");
                        if (strDel != "")
                            strDel += ",";
                        strDel += btnItem.CommandArgument;
                    }
                }
            }
            return strDel;
        }
        private void HideGridCol(int _i)
        {
            grdListNews.Columns[_i].Visible = false;
        }

       
       

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Portal.BO.SearchHelper objhelp = new Portal.BO.SearchHelper();
            //string strcpmode = Request.QueryString["cpmode"].ToString();
            txtKeyword.Text = txtKeyword.Text.Replace("'", "");
            string[] strKeys = txtKeyword.Text.Split(" ".ToCharArray());
            string strKey = objhelp.getAndCond("News_Title", strKeys);
            string strCat = cboCategory.SelectedValue;
            string strAndCat = "";
            if (strCat != "0")
                strAndCat = " AND Cat_ID=" + strCat;

            objListNewsSource.SelectParameters[0].DefaultValue = " News_Status=3 AND " + strKey + strAndCat;
            objListNewsSource.SelectParameters[1].DefaultValue = "True";
                    
            
        }
        /// <summary>
        /// Ham thuc hien lenh xoa that nhung tin da duoc chon trong hom rac
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lnkRealDel_Click(object sender, EventArgs e)
        {
            string strcpmode = Request.QueryString["cpmode"].ToString();
            objListNewsSource.DeleteParameters[0].DefaultValue = getCheckedRow();
            objListNewsSource.Delete();
            Response.Redirect("office/" + strcpmode + ".chn");
        }
        protected void LinkFeedBackAll_Click(object sender, EventArgs e)
        {
            string strcpmode = Request.QueryString["cpmode"].ToString();
            objListNewsSource.UpdateParameters[1].DefaultValue = "5";
            objListNewsSource.UpdateParameters[2].DefaultValue = getCheckedRow();
            objListNewsSource.Update();
            Response.Redirect("office/" + strcpmode + ".chn");
        }

        protected void LinkApproval_Click(object sender, EventArgs e)
        {
            string strcpmode = Request.QueryString["cpmode"].ToString();
            objListNewsSource.UpdateParameters[1].DefaultValue = "3";
            objListNewsSource.UpdateParameters[2].DefaultValue = getCheckedRow();
            objListNewsSource.Update();
            Response.Redirect("office/" + strcpmode + ".chn");
        }
    }
}